<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	public function _initAutoload(){
		$autoloader = new Zend_Application_Module_Autoloader ( array ('namespace' => '', 'basePath' => APPLICATION_PATH )
		
		);
		
		return $autoloader;
	
	}

	protected function _initDb() {
			$dbOption = $this->getOption('resources');
			$dbOption = $dbOption['db'];
			
			// Setup database
			$db = Zend_Db::factory($dbOption['adapter'],$dbOption['params']);
			$db->setFetchMode(Zend_Db::FETCH_ASSOC);
			$db->query("SET NAMES 'utf8'");
			$db->query("SET CHARACTER SET 'utf8'");
			 
			Zend_Registry::set('connectDB',$db);
		
			//Khi thiet lap che do nay model moi co the su dung duoc
			Zend_Db_Table::setDefaultAdapter($db);
			Zend_Db_Table_Abstract::setDefaultAdapter($db);
			// Return it, so that it can be stored by the bootstrap
			return $db;
		}
		
		
	
		protected function _initSession()
		{
		
			$config = array(
					'name'              => 'session', //table name as per Zend_Db_Table
					'primary'           => array(
							'session_id',   //the sessionID given by PHP
							'save_path',    //session.save_path
							'name',         //session name
					),
		
					'primaryAssignment' => array(
							//you must tell the save handler which columns you
							//are using as the primary key. ORDER IS IMPORTANT
							'sessionId', //first column of the primary key is of the sessionID
							'sessionSavePath', //second column of the primary key is the save path
							'sessionName', //third column of the primary key is the session name
					),
					'modifiedColumn'    => 'modified',     //time the session should expire
					'dataColumn'        => 'session_data', //serialized data
					'lifetimeColumn'    => 'lifetime',     //end of life for a specific record
		
			);
		
			//Tell Zend_Session to use your Save Handler
			Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
		
			//start your session
		
			Zend_Session::start();
		
		}
		
		
}

